<?php
!defined('ADMIN') && exit('Not allowed to directly view page');
	require_once(DEDEINC.'/datalistcp.class.php');
	define('DEDEASK' ,1);
	//require_once(DEDEROOT.'/ask/include/asktype.inc.php');
	//
	//问答分类
	$query = "select id, name, asknum, reid from `#@__asktype` order by disorder desc, id asc";
	$dsql->Execute('me',$query);
	$tids = $tid2s = $asktypes = array();
	while($asktype = $dsql->getarray())
	{
		if($asktype['reid'] == 0)
		{
			$tids[] = $asktype;
		}else
		{
			$tid2s[] = $asktype;
		}

	}
	foreach($tids as $tid)
	{
		$asktypes[] = $tid;
		foreach($tid2s as $key => $tid2)
		{
			if($tid2['reid'] == $tid['id'])
			{
				$asktypes[] = $tid2;
				unset($tid2s[$key]);
			}
		}
	}
	//
	if($dopost == 'add')
	{
		// 没选定上传文件，0 文件类型不允许, -2 保存失败，其它：返回上传后的文件名
		$upfile = AdminUpload('photo');
		$msg ='';
		if($upfile=='-1')
		{
			$msg = "<script language='javascript'>
					alert('你没指定要上传的文件或文件大小超过限制！');
				</script>";
		}
		else if($upfile=='-2')
		{
			$msg = "<script language='javascript'>
					alert('上传文件失败，请检查原因！');
				</script>";
		}
		else if($upfile=='0')
		{
			$msg = "<script language='javascript'>
					alert('文件类型不正确！');
				</script>";
		}
		if($msg){ echo $msg;exit;}
		$dsql->ExecuteNoneQuery("insert into `#@__doctor` (name,qq,photo,hospitalid,professions,ifcheck,description,seo,keyword,keyword_description,`link`,recommend,station,position)
			values( '$name','$qq','$upfile','$hospital','$professions','0','$description','$seo','$keyword','$keyword_description','$link','$recommend','$station','$position')");
		showmsg('添加信息成功',"?do=ask_doctor");
	}
	else if($dopost == 'save')
	{
		$id = (int)$id;
		if(!empty($_FILES['photo']['name'])){
			$upfile = AdminUpload('photo');
			$msg ='';
			if($upfile=='-1')
			{
				$msg = "<script language='javascript'>
						alert('你没指定要上传的文件或文件大小超过限制！');
					</script>";
			}
			else if($upfile=='-2')
			{
				$msg = "<script language='javascript'>
						alert('上传文件失败，请检查原因！');
					</script>";
			}
			else if($upfile=='0')
			{
				$msg = "<script language='javascript'>
						alert('文件类型不正确！');
					</script>";
			}
			$file= "photo='$upfile',";
		}
		$dsql->ExecuteNoneQuery("update  `#@__doctor` set name='$name',qq='$qq',
		$file hospitalid='$hospital',professions='$professions',ifcheck='0',description='$description',seo='$seo',keyword='$keyword',keyword_description='$keyword_description',`link`='$link',recommend='$recommend',station='$station',position='$position' where id=$id");
		showmsg('修改信息成功',"?do=ask_doctor");
	}
	else if($action == 'delete' && $id)
	{
		$id = (int)$id;
		$dsql->ExecuteNoneQuery("delete from `#@__doctor` where id=$id");
		showmsg('删除信息成功',"?do=ask_doctor");
	}
	else
	{
		$hospitalsql = "Select * from `#@__hospital`";
		$dsql->Execute('me',$hospitalsql);
		while($row = $dsql->getarray())
		{
			$hospitals[] = $row;
		}
		if($action == 'update' && $id)
		{
			$id = (int)$id;
			$doctor = $dsql->getone('Select * From `#@__doctor` where id='.$id);
		}
		$dtp = new DedeTemplate();
		$dtp->LoadTemplate(DEDEADMIN.'/templets/ask_doctor_add.htm');
		$dtp->Display();
	}


?>